package com.jumper.property.comparer.core.diff.value;

import com.jumper.property.comparer.core.annotations.DiffKey;
import com.jumper.property.comparer.core.annotations.UnionDisplayKey;
import com.jumper.property.comparer.core.annotations.UnionKey;
import com.jumper.property.comparer.core.constant.TypeConstant;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 原始类型包装
 */
@Getter
@Setter
public class PrimitiveWrapper implements Serializable {

    /**
     * 包装值
     */
    @UnionKey
    @UnionDisplayKey
    @DiffKey(name = "值")
    private Object value;

    public static PrimitiveWrapper instance(Object value) {
        PrimitiveWrapper wrapper = new PrimitiveWrapper();
        wrapper.value = value;
        return wrapper;
    }

    /**
     * 是否是原始类型
     */
    public static boolean isPrimitive(Class<?> cls) {
        if (cls == null) {
            return false;
        }
        if (cls.isPrimitive()) {
            return true;
        }
        return TypeConstant.PRIMITIVE_TYPE_LIST.contains(cls.getName());
    }
}
